package cn.wolfcode.brand.web.controller;

import cn.wolfcode.brand.commmon.JsonResult;

import cn.wolfcode.brand.domain.Brand;
import cn.wolfcode.brand.query.BrandQueryObject;
import cn.wolfcode.brand.service.IBrandService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("brand")
public class BrandController {

    @Autowired
    IBrandService brandService;

    @GetMapping("list")
    public JsonResult list() {
        BrandQueryObject qo = new BrandQueryObject();
        Page<Brand> brands = brandService.queryPage(qo);
        return JsonResult.success(brands);
    }

    @PostMapping("add")
    public JsonResult add(Brand brand) {
       brandService.save(brand);
       return JsonResult.success();
    }

    @GetMapping("detail/{id}")
    public JsonResult detail(@PathVariable("id") Long id) {
        Brand brand = brandService.getById(id);
        System.out.println(brand);
        return JsonResult.success(brand);
    }

    @PutMapping("update")
    public JsonResult update(Brand brand) {
         brandService.updateById(brand);
        return JsonResult.success();
    }

    @DeleteMapping("delete")
    public JsonResult delete(Long id) {
        brandService.removeById(id);
        return JsonResult.success();
    }
}
